package com.zmn.oms.dubbo.impl.normal.conf;

import com.google.common.collect.Lists;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.oms.common.dro.normal.conf.ConfOrderTagDRO;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.dubbo.interfaces.normal.conf.ConfOrderTagListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.conf.ordertag.ConfOrderTag;
import com.zmn.oms.model.entity.conf.ordertag.ConfOrderTagQuery;
import com.zmn.oms.services.interfaces.conf.ordertag.ConfOrderTagService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

/**
 * 类描述：工单标记查询
 *
 * @author wangxiaokun
 * @since 2022/03/25 15:17
 */
@DubboService(loadbalance = "roundrobin", timeout = 10000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class ConfOrderTagListRemoteServiceImpl implements ConfOrderTagListRemoteService {

    @Autowired
    private ConfOrderTagService confOrderTagService;

    @Override
    public ResponseDTO<ConfOrderTagDRO> getConfOrderTagById(Integer id) {
        ConfOrderTag confOrderTag = confOrderTagService.findConfById(id);
        if (Objects.isNull(confOrderTag)) {
            return ResponseDTO.success(null);
        }
        ConfOrderTagDRO dro = new ConfOrderTagDRO();
        dro.setId(confOrderTag.getId());
        dro.setTagName(confOrderTag.getTagName());
        dro.setTagShortName(confOrderTag.getTagShortName());
        dro.setCategoryIds(confOrderTag.getCategoryIds());
        dro.setColor(confOrderTag.getColor());
        dro.setRemark(confOrderTag.getRemark());
        dro.setStatus(confOrderTag.getStatus());
        return ResponseDTO.success(dro);
    }

    @Override
    public ResponseDTO<List<ConfOrderTagDRO>> listConfOrderTagByCategoryIds(List<Integer> categoryIds, Integer status) {
        ConfOrderTagQuery query = new ConfOrderTagQuery();
        query.setCategoryIdList(categoryIds);
        query.setStatus(status);
        List<ConfOrderTag> confOrderTagList = confOrderTagService.listByQuery(query);
        if (CollectionUtil.isNullOrEmpty(confOrderTagList)) {
            return ResponseDTO.success(Lists.newArrayList());
        }
        List<ConfOrderTagDRO> droList = Lists.newArrayListWithCapacity(confOrderTagList.size());
        confOrderTagList.forEach(confOrderTag -> {
            ConfOrderTagDRO dro = new ConfOrderTagDRO();
            dro.setId(confOrderTag.getId());
            dro.setTagName(confOrderTag.getTagName());
            dro.setTagShortName(confOrderTag.getTagShortName());
            dro.setCategoryIds(confOrderTag.getCategoryIds());
            dro.setColor(confOrderTag.getColor());
            dro.setRemark(confOrderTag.getRemark());
            dro.setStatus(confOrderTag.getStatus());
            droList.add(dro);
        });
        return ResponseDTO.success(droList);
    }
}
